<?php
define("DEFAULT_LB_PRICE",1000);
define("DEFAULT_LB_CURRENCY",'VND');
define('PAYMENT_METHOD_DEFAULT',0);
define("BAOKIM_EMAIL_PAYMENT", "thewaytopublishabook@gmail.com");
define("BAOKIM_PRODUCT_PRICE", DEFAULT_LB_PRICE);
define("BAOKIM_PRODUCT_QUANTITY",1);
define("MIN_BATCH_HOUR","20:00:00");
define("MAX_BATCH_HOUR","21:00:00");

function lb_get_default_price(){
  return variable_get("DEFAULT_LB_PRICE", DEFAULT_LB_PRICE);
}

function lb_get_default_currency(){
  return variable_get("DEFAULT_LTOD_CURRENCY", DEFAULT_LB_CURRENCY);
}

function lb_get_date_field_from_date($date){
  return array('month' => date('n',$date),'day'=> date('j',$date),'year'=>date('Y',$date));
}

function lb_get_default_start_date(){
  $next_monday = strtotime('next monday');
  return array('month' => date('n',$next_monday),'day'=> date('j',$next_monday),'year'=>date('Y',$next_monday));
}
function lb_get_default_end_date(){
  $next_monday = strtotime('next monday');
  $next_friday = strtotime('next friday',$next_monday);
  return array('month' => date('n',$next_friday),'day'=> date('j',$next_friday),'year'=>date('Y',$next_friday));
}
function lb_number_format($number,$decimals){
  return number_format($number,$decimals,variable_get("dec_point", ','),variable_get("thousands_sep", '.'));
}
function lb_is_running_batch(){
  //TODO thay doi thanh kiem tra tu 8h den 9h toi
  //thay doi thanh kiem tra tu 8h den 9h toi
  //DONE
  //$sql = "SELECT COUNT(*) FROM {lastbuyer_batch}  WHERE status=1";
  //return db_result(db_query($sql)) >0;
  
  $current = date('H:i:s',time());
  return strcmp(MIN_BATCH_HOUR, $current) >=0 &&strcmp(MAX_BATCH_HOUR, $current)<=0;
}
function get_all_sponsor(){
  $sql = 'SELECT * FROM {sponsor} ORDER BY weight';
  $query = db_query($sql);
  while (($next_record = db_fetch_array($query)) !== FALSE) {
    $result[] = $next_record;
  }

  return $result;
}
function get_lastest_transaction(){
  $query =db_query_range("SELECT * FROM {lastbuyer_transaction} ORDER BY buy_date DESC", 0, 2);
  while (($next_record = db_fetch_array($query)) !== FALSE) {
    $result[] = $next_record;
  }
  return $result;
}
function get_pager_index($function){
  $result = 0;
  switch ($function) {
    case 'sponsor_block_pager':
      $result =1 ;
      break;
    case 'sponsor_list_pager':
      $result =2 ;
      break;
	case 'list_transaction_all':
      $result =3 ;
      break; 
    case 'list_transaction_all_admin':
      $result =4 ;
      break;
    case 'user_view_transactions':
      $result =5 ;
      break;
	case 'updateall_traceid':
	  $result =6;
      break;
	case 'view_done_transactions':
	  $result =7;
      break;
	case 'user_view_points':
	  $result =8;
      break;
    default:
      ;
      break;
  }
  return $result;
}